package treeset.demo01;
//用TreeSet储存学生对象,并遍历

import treeset.demo01.Student;

import java.util.TreeSet;

public class TreeSetDemo {

    //入口
    public static void main(String[] args) {
        //思路
        //创建学生对象
        //创建TreeSet集合对象
        //将学生对象添加到TreeSet集合中
        //遍历

        //1.创建对象
        Student student = new Student("王子文",23);
        Student student2 = new Student("张子凡",25);
        Student student3 = new Student("李林夕",22);
        Student student4 = new Student("郭东辉",18);
        Student student5 = new Student("切本那",23);

        //2.创建TreeSet集合对象
        TreeSet<Student> treeSet = new TreeSet<>();

        //将学生对象添加到TreeSet集合中
        treeSet.add(student);
        treeSet.add(student2);
        treeSet.add(student3);
        treeSet.add(student4);
        treeSet.add(student5);

        //遍历
        treeSet.forEach(student1 -> System.out.println(student1));


    }
}
